var page = require('webpage').create(),
    system = require('system'),
    address;

if (system.args.length === 1) {
    console.log('Usage: loadspeed.js <some URL>');
    phantom.exit(1);
} else {
    name = system.args[1];
    address = system.args[2];
    console.log(name + ' ' + address);
    page.open(address, function(status){
        if (status !== 'success') {
            console.log('no ' + name + ' ' + address);
        } else {
            var title = page.evaluate(function(){
                return document.title;
            });
            var host = page.evaluate(function(){
                return window.location.host;
            });
            if (host){
                address = 'http://' + host;
            }
            console.log('yes ' + name + ' ' + address + ' ' + title);
        }
        phantom.exit();
    });
}

setTimeout(function(){
    console.log('timeout ' + name + ' ' + address);
    phantom.exit();
}, 20000);
